   <!-- Main content -->
    <section class="content">

	  <div class="row">
        <div class="col-xs-12">
          <div class="box box-info">
            <div class="box-header">
              <h3 class="box-title">用户组管理</h3>  &emsp;<button type="button" data-toggle="modal" data-target="#exampleModal" class="btn btn-sm btn-success">新建用户组</button>

              <div class="box-tools">
                <button type="button" id="refresh" class="btn btn-default btn-sm" title="刷新当前页"><i class="fa fa-refresh"></i></button>
              </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
              <table class="table table-hover">
               <tbody><tr>
					<th>ID</th>
                  <th>用户组名称</th>
                  <th>状态</th>
                  <th>拥有权限</th>
				  <th>操作</th>
                </tr>
       	<volist name="group" id="vo">
        <tr>
		<td>{$i}</td>
		<td>{$vo.title}</td>
		<td><switch name="vo['status']">
        <case value="1"><span class="btn btn-success btn-xs">正常</span></case>
        <case value="0"><span class="btn btn-danger btn-xs">禁用</span></case>
        <default />未知
        </switch></td>
		<td>{$vo.rules}</td>
		<td>
      <a href="__APP__/admin/admin/editgroup/{$vo.id}" class="btn btn-success btn-xs ajax_return">查看/修改</a>
      <a href="__APP__/admin/admin/groupstate/{$vo.id}" class="btn btn-warning btn-xs ajax_return">开启/禁用</a>
      <a href="__APP__/admin/admin/delgroup/{$vo.id}" class="btn btn-danger btn-xs ajax_return">删除</a>
    </td>
		</tr>
		</volist>
	     
              </tbody></table>
            </div>
            <!-- /.box-body -->

			<div class="box-footer clearfix">
				<ul class="pagination pagination-sm no-margin pull-left">
					共有  {$page.count} 条记录
				</ul>
              <ul class="pagination pagination-sm no-margin pull-right pagelist">
                  <for start="0" end="$page.pages" >
                  <if condition="$page.page == $i+1"><li class="active"><a href="__APP__/admin/admin/authgroup/{$i+1}">{$i+1}</a></li>
                  <else/><li><a href="__APP__/admin/admin/authgroup/{$i+1}">{$i+1}</a></li>
                  </if>
                </for>
              </ul>
            </div>

          </div>
          <!-- /.box -->
        </div>
      </div>

    </section>
    <!-- /.content -->

<div class="modal modal-success fade" id="exampleModal" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="addgroup" method="post" action="__MODULE__/admin/addgroup">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">新建用户组</h4>
      </div>
              <div class="modal-body">
                <div class="form-group">
                  <label for="inputname" class="col-sm-2 control-label">用户组名称</label>
          <div class="col-sm-10">
                    <input type="text" class="form-control" name="title" id="inputname" placeholder="用户组名称">
                  </div>
                </div>
                
              <div class="form-group">
                  <label class="col-sm-2 control-label">用户组权限</label>
                  <div class="col-sm-10">
                          <volist name="class" id="vo">
                          <h5 class="box-title">{$vo.classname} &gt;&gt;</h5>
                              <volist name="vo['rules']" id="rul">
                                  <label><input type="checkbox" name="rules[]" value="{$rul.id}" />{$rul.title}</label>&nbsp;&nbsp;&nbsp;&nbsp;
                              </volist>
                          </volist>
                  </div>
                </div>
                </div>
              <!-- /.modal-body -->
              <div class="modal-footer">
                <p class="pull-left ajaxreturnp"></p>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info pull-right subtn">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
      </div>
    </div>
  </div>
</div>
<!--新建用户组-->
<div class="modal modal-success fade" id="editModal" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="editgroup" method="post" action="__MODULE__/admin/editgroup">
      <input type="hidden" name="id" id="groupid">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">修改用户组</h4>
      </div>
              <div class="modal-body">
                <div class="form-group">
                  <label for="inputname" class="col-sm-2 control-label">用户组名称</label>
          <div class="col-sm-10">
                    <input type="text" class="form-control" name="title" id="inputname2">
                  </div>
                </div>
                
              <div class="form-group">
                  <label class="col-sm-2 control-label">用户组权限</label>
                  <div class="col-sm-10">
                          <volist name="class" id="vo">
                          <h5 class="box-title">{$vo.classname} &gt;&gt;</h5>
                              <volist name="vo['rules']" id="rul">
                                  <label><input type="checkbox" name="rule[]" value="{$rul.id}" />{$rul.title}</label>&nbsp;&nbsp;&nbsp;&nbsp;
                              </volist>
                          </volist>
                  </div>
                </div>
                </div>
              <!-- /.modal-body -->
              <div class="modal-footer">
                <p class="pull-left ajaxreturnp"></p>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-info pull-right subtn">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
      </div>
    </div>
  </div>
</div>
<!--修改用户组-->
<div class="modal modal-warning fade" id="statusModal" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="statusadmin" method="post" action="__MODULE__/admin/groupstate">
      <input type="hidden" name="id" id="inputhidden2">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">开启/禁用用户组</h4>
      </div>
      <div class="modal-body">
        <p>确定要开启/禁用 [<span id="groupname2"></span>] 吗？其所属成员也将被开启/禁用！</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-warning subtn">确定</button>
      </div>
      </form>
    </div>
  </div>
</div>
<!--开启禁用用户组和用户组所属成员-->
<!--修改用户组-->
<div class="modal modal-danger fade" id="delModal" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <form class="form-horizontal" id="delgroup" method="post" action="__MODULE__/admin/delgroup">
      <input type="hidden" name="id" id="inputhidden3">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">删除用户组</h4>
      </div>
      <div class="modal-body">
        <p>确定要删除 [<span id="groupname3"></span>] 吗？为安全起见其所属成员不会被删除！</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-danger subtn">确定</button>
      </div>
      </form>
    </div>
  </div>
</div>
<!--删除用户组并删除所属成员-->

<script type="text/javascript">
  $(".subtn").on("click",function(){
      var formdata = $(this).parent().parent().serialize();
      var url = $(this).parent().parent().attr("action");
      var method = $(this).parent().parent().attr("method");
      if (method == "post") {
        $.post(url,formdata,function(data){
          if (data == '1') {
            $(".modal").modal('hide');
          }else{
            $(".ajaxreturnp").text("操作失败");
          }
        });
      }else if(method == "get"){
          $.get(url,function(data){
              if (data=='1') {
                $(".modal").modal('hide');
              }else{
                $(".ajaxreturnp").text("操作失败");
              }
          });
      } 
  });

  $(".ajax_return").on("click",function(){
      var url = $(this).attr("href");
      var pathurl = url.split("/");
      var groupname = $(this).parent().siblings().eq(1).text();
      var rules = $(this).parent().siblings().eq(3).text().split(",");
      /**修改用户组**/
      if (pathurl[pathurl.length-2] == "editgroup") {
            $("#groupid").val(pathurl[pathurl.length-1]);
            $("#inputname2").val(groupname);
            $("input[name='rule[]']").each(function(){
              if ($.inArray($(this).val(),rules) > -1) {
                $(this).attr("checked","true");
              }
            });
            $("#editModal").modal('show');
      /**开启禁用用户组**/ 
      }else if(pathurl[pathurl.length-2] == "groupstate"){
          $("#inputhidden2").val(pathurl[pathurl.length-1]);
          $("#groupname2").text(groupname);
          $("#statusModal").modal('show');
      /**删除用户组**/
      }else if(pathurl[pathurl.length-2] == "delgroup"){
          var username = $(this).parent().siblings().eq(1).text();
          $("#inputhidden3").val(pathurl[pathurl.length-1]);
          $("#groupname3").text(groupname);
          $("#delModal").modal('show');
      }else{
        if(url&&url!='/'&&url!="#"){
          $.get(url,function(data){
              if (data=='1') {
                refresh();
              }else{
                alert("修改失败");
              }
          });
        }
      } 
  });

  $('.modal').on('hidden.bs.modal', function (){
      refresh();
  })

  $("#refresh").on("click",function(){
      refresh();
  });

  function refresh(){
      var pagei = $(".pagelist li.active").text();
      $("#mcont").load("__MODULE__/admin/authgroup/"+pagei);
  }
</script>